home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWToolbx / FWColorP.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  5.0 KB  |  184 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWColorP.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWCOLORP_H
  13. #include "FWColorP.h"
  14. #endif
  15.  
  16. #ifndef FWGCONST_H
  17. #include "FWGConst.h"
  18. #endif
  19.  
  20. #ifndef FWSTRMRW_H
  21. #include "FWStrmRW.h"
  22. #endif
  23.  
  24. #if defined(FW_BUILD_MAC) && !defined(__COLORPICKER__)
  25. #include <ColorPicker.h>
  26. #endif
  27.  
  28. //========================================================================================
  29. // Runtime info
  30. //========================================================================================
  31.  
  32. #ifdef FW_BUILD_MAC    
  33. #pragma segment fwtoolbx
  34. #endif
  35.  
  36.  
  37. //========================================================================================
  38. //    class FW_CColorPicker
  39. //========================================================================================
  40.  
  41. //----------------------------------------------------------------------------------------
  42. //    FW_CColorPicker::FW_CColorPicker
  43. //----------------------------------------------------------------------------------------
  44.  
  45. FW_CColorPicker::FW_CColorPicker() :
  46.     fColor()
  47. {
  48.     for (unsigned short i = 0; i < 16; ++i)
  49.         fCustomColors[i] = FW_kRGBWhite;
  50. }
  51.  
  52. //----------------------------------------------------------------------------------------
  53. //    FW_CColorPicker::FW_CColorPicker
  54. //----------------------------------------------------------------------------------------
  55.  
  56. FW_CColorPicker::FW_CColorPicker(FW_CReadableStream& stream) :
  57.     fColor()
  58. {
  59.     Read(stream);
  60. }
  61.  
  62. //----------------------------------------------------------------------------------------
  63. //    FW_CColorPicker::~FW_CColorPicker
  64. //----------------------------------------------------------------------------------------
  65.  
  66. FW_CColorPicker::~FW_CColorPicker()
  67. {
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. //    FW_CColorPicker::SetColor
  72. //----------------------------------------------------------------------------------------
  73.  
  74. void FW_CColorPicker::SetColor(const FW_CColor& color)
  75. {
  76.     fColor = color;
  77. }
  78.  
  79. //----------------------------------------------------------------------------------------
  80. //    FW_CColorPicker::GetColor
  81. //----------------------------------------------------------------------------------------
  82.  
  83. FW_CColor FW_CColorPicker::GetColor() const
  84. {
  85.     return fColor;
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. //    FW_CColorPicker::PickNewColor
  90. //----------------------------------------------------------------------------------------
  91.  
  92. FW_Boolean FW_CColorPicker::PickNewColor()
  93. {
  94.     FW_Boolean result = FALSE;
  95.     
  96. #ifdef FW_BUILD_WIN
  97. #if 0
  98.     BR_CEventHandler::EventHandlerID dismisser = cmdCancel;
  99.     BR_CApplication *App = BR_CApplication::GetApplication();
  100.  
  101.     CHOOSECOLOR cc;
  102.  
  103.     // Fill Windows parameters structure
  104.     cc.lStructSize = sizeof(cc);
  105.     cc.hwndOwner = BR_CAppDesktop::GetAppDesktop()->GetPlatformWindow();
  106.     cc.rgbResult = fColor.GetRGB();
  107.     cc.lpCustColors = fCustomColors;
  108.     cc.Flags = CC_RGBINIT;
  109.  
  110.     App->SetAppModal();
  111.  
  112.     // Call a function on COMMDLG.DLL
  113.     if (ChooseColor(&cc))
  114.     {
  115.         // Set result to Ok
  116.         dismisser = cmdOk;
  117.  
  118.         // And update our color value
  119.         fColor = cc.rgbResult;
  120.     }
  121.  
  122.     App->ClearAppModal();
  123. #endif
  124. #endif
  125.  
  126. #ifdef FW_BUILD_MAC
  127.  
  128.     RGBColor inColor = fColor;
  129.     RGBColor outColor;
  130.  
  131.     Point where = {-1, - 1};
  132.         
  133.     if (::GetColor(where, (ConstStr255Param)"\p", &inColor, &outColor))
  134.     {
  135.         result = TRUE;
  136.         
  137.         // And update our color value
  138.         fColor = outColor;
  139.     }
  140. #endif
  141.  
  142.     return result;
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CColorPicker::Read
  147. //----------------------------------------------------------------------------------------
  148.  
  149. void FW_CColorPicker::Read(FW_CReadableStream& stream)
  150. {
  151.     for (short i = 0; i < 16; ++i)
  152.         stream >> fCustomColors[i];
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    FW_CColorPicker::Write
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void FW_CColorPicker::Write(FW_CWritableStream& stream) const
  160. {
  161.     for (short i = 0; i < 16; ++i)
  162.         stream << fCustomColors[i];
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    FW_CColorPicker::operator>>
  167. //----------------------------------------------------------------------------------------
  168.  
  169. FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CColorPicker& colorPicker)
  170. {
  171.     colorPicker.Read(stream);
  172.     return stream;
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    FW_CColorPicker::operator<<
  177. //----------------------------------------------------------------------------------------
  178.  
  179. FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CColorPicker& colorPicker)
  180. {
  181.     colorPicker.Write(stream);
  182.     return stream;
  183. }
  184.